$.extend($.fn, {
    hideJmodal: function() {
        $('#jmodal-overlay').animate({ opacity: 0 }, function() { $(this).css('display', 'none') });
        $('#jquery-jmodal').animate({ opacity: 0 }, function() { $(this).css('display', 'none') });
    },
    jmodal: function(setting) {
        var ps = $.fn.extend({
            data: {},
            marginTop: 200,
			buttonText: { ok: '确定', cancel: '取消' },
            okEvent: function(e) { },
            initWidth: 400,
            fixed: false,
            title: '提示信息',
            content: 'This is a Dialog Content!'
        }, setting);

		if(ps.buttonText.ok == '确定'){
			ps.btnContent = '';
		}else{
			ps.btnContent = '<div class="jmodal-bottom"><input type="button" value="df' + ps.buttonText.ok + '" />&nbsp;&nbsp;<input type="button" value="' + ps.buttonText.cancel + '" /></div>';
		}

        ps.docWidth = $(document).width();
        ps.docHeight = $(document).height();

        if ($('#jquery-jmodal').length == 0) {
            $('<div id="jmodal-overlay" class="jmodal-overlay"/>' +
                '<div class="jmodal-main" id="jquery-jmodal" >' +
                    '<table cellpadding="0" cellspacing="0">' +
                        '<tr>' +
                            '<td class="jmodal-top-left"></td>' +
                            '<td class="jmodal-border-top"></td>' +
                            '<td class="jmodal-top-right"></td>' +
                        '</tr>' +
                    '<tr>' +
                        '<td class="jmodal-border-left">&nbsp;</td>' +
                        '<td >' +
                            '<div class="jmodal-title" />' +
                            '<div class="jmodal-content" id="jmodal-container-content" />' +
								ps.btnContent + 
                        '</td>' +
                        '<td class="jmodal-border-right">&nbsp;</td>' +
                    '</tr>' +
                    '<tr>' +
                        '<td class="jmodal-bottom-left"></td>' +
                        '<td class="jmodal-border-bottom"></td>' +
                        '<td class="jmodal-bottom-right"></td>' +
                    '</tr>' +
                    '</table>' +
                '</div>').appendTo($(document.body));
            //$(document.body).find('form:first-child') || $(document.body)
        }
        else {
            $('#jmodal-overlay').css({ opacity: 0, 'display': 'block' });
            $('#jquery-jmodal').css({ opacity: 0, 'display': 'block' });
        }
        $('#jmodal-overlay').css({
            height: ps.docHeight,
            opacity: 0
        }).animate({ opacity: 0.3 });

        $('#jquery-jmodal').css({
            position: (ps.fixed ? 'fixed' : 'absolute'),
            width: ps.initWidth,
            left: (ps.docWidth - ps.initWidth) / 2,
            top: (ps.marginTop + document.documentElement.scrollTop)
        }).animate({ opacity: 1 });

        $('#jquery-jmodal')
            .find('.jmodal-title')
                //.html(ps.title)
				.html('<span style="float:left;" mce_style="float:left;">' + ps.title + '</span>' + '<span style="float:right;margin-right:8px;" mce_style="float:right;margin-right:8px;"> <a href="javascript:void(0)" mce_href="javascript:void(0)" id="jmodal-title-close" style="color:#fff;font-size:12px;font-weight:nomal">关闭</a></span>')  
                    .next()
                        .next()
                            .children('input:first-child')
								
                                .attr('value', ps.buttonText.ok)
                                    .unbind('click')
                                        .one('click', function(e) {
                                            var args = {
                                                complete: $.fn.hideJmodal
                                            };

                                            ps.okEvent(ps.data, args);
                                        })
                                            .next()
                                                .attr('value', ps.buttonText.cancel)
                                                    .one('click', $.fn.hideJmodal);
								
        if (typeof ps.content == 'string') {
            $('#jmodal-container-content').html(ps.content);
        }
        if (typeof ps.content == 'function') {
            var e = $('#jmodal-container-content');
            e.holder = $('#jquery-jmodal');
            ps.content(e);
        }
		$('#jmodal-title-close').mouseup($.fn.hideJmodal);
    }
})


